package hz.mobileproject.pda.toolsmanager.utils;

import com.blankj.utilcode.util.SPUtils;

import hz.mobileproject.pda.entity.request.Request_loadPersioneInfo;
import hz.mobileproject.pda.entity.request.Request_loadPoliceInfo;
import hz.mobileproject.pda.entity.response.Response_loadPoliceInfo;
import hz.mobileproject.pda.entity.response.Rp_loadPrisonerInfo;
import hz.mobileproject.pda.listener.CustomNetCallBack;
import hz.mobileproject.pda.network.Constance;
import hz.mobileproject.pda.toolsmanager.bean.request.RQ_FreeCountTool;
import hz.mobileproject.pda.toolsmanager.bean.request.RQ_GetGrantedTools;
import hz.mobileproject.pda.toolsmanager.bean.request.RQ_SelStation;
import hz.mobileproject.pda.toolsmanager.bean.request.RQ_SelToolInfo;
import hz.mobileproject.pda.toolsmanager.bean.response.RP_StationInfo;
import hz.mobileproject.pda.toolsmanager.bean.response.RP_ToolSysSet;
import hz.mobileproject.pda.utils.HttpRqUtils;

/**
 * Created by Lc on 2018/5/17.
 */

public class ToolCommonHttpUtils {

    /**
     * 请求网络接口获取民警信息
     *
     * @param scanStr
     */
    public static void getPoliceInfoFromSer(String scanStr,CustomNetCallBack policeInfoCallback) {
        scanStr = scanStr.indexOf("P") == 0 ? scanStr.substring(1) : scanStr;
        Request_loadPoliceInfo rq_lpi = new Request_loadPoliceInfo();
        rq_lpi.setCusNumber(SPUtils.getInstance("app_login").getString(Constance.SP_CUSNUMBER));
        rq_lpi.setPoliceCode(scanStr);
        //发送获取民警信息接口请求
        HttpRqUtils.httpPost(Constance.BASE_URL + Constance.URL_LOAD_POLICE_INFO, rq_lpi, policeInfoCallback);
    }


    /**
     * 请求网络接口获取罪犯信息
     *
     * @param scanStr
     */
    public static void getPrisonerInfoFromSer(String scanStr,Response_loadPoliceInfo mPoliceInfo,CustomNetCallBack prisonerInfoCallback) {
        Request_loadPersioneInfo rq_lpi = new Request_loadPersioneInfo();
        rq_lpi.setCusNumber(mPoliceInfo.getCus_number() + "");
        rq_lpi.setPrisonerId(scanStr);
        //发送获取罪犯信息接口请求
        HttpRqUtils.httpPost(Constance.BASE_URL + Constance.URL_LOAD_PRISONER_INFO, rq_lpi, prisonerInfoCallback);
    }
    
    
    /**
     * 请求网络接口获取工位信息
     *
     * @param scanStr
     */
    public static void getWorkStationInfoFromSer( String scanStr,RP_ToolSysSet mToolSystemSet, Response_loadPoliceInfo mPoliceInfo,CustomNetCallBack callBack) {
        scanStr = scanStr.indexOf(mToolSystemSet.getStationPrefix()) == 0 ? scanStr.substring(2) : scanStr;
        RQ_SelStation selStation = new RQ_SelStation();
        selStation.setCus_number(mPoliceInfo.getCus_number() + "");
        selStation.setStation_id(scanStr);
        HttpRqUtils.httpPost(Constance.BASE_URL + Constance.URL_TOOL_SEL_STATION, selStation,callBack);
    }


    /**
     * 请求网络接口获取工具信息
     *
     * @param scanStr
     */
    public static void getToolInfoFromSer(String scanStr, RP_ToolSysSet mToolSystemSet, Response_loadPoliceInfo mPoliceInfo,CustomNetCallBack callBack) {
        scanStr = scanStr.indexOf(mToolSystemSet.getToolPrefix()) == 0 ? scanStr.substring(2) : scanStr;
        RQ_SelToolInfo selToolInfo = new RQ_SelToolInfo();
        selToolInfo.setCus_number(mPoliceInfo.getCus_number() + "");
        selToolInfo.setTool_id(scanStr);
        HttpRqUtils.httpPost(Constance.BASE_URL + Constance.URL_TOOL_SEL_TOOL_INFO, selToolInfo,callBack);
    }
    
    
    /**
     * 请求网络接口获取库存信息
     */
    public static void getFreeToolsCountFromSer(Response_loadPoliceInfo mPoliceInfo,CustomNetCallBack callBack) {
        RQ_FreeCountTool freeCountTool = new RQ_FreeCountTool();
        freeCountTool.setCus_number(mPoliceInfo.getCus_number() + "");
        freeCountTool.setDprt_id(mPoliceInfo.getDepartment_id()+"");
        HttpRqUtils.httpPost(Constance.BASE_URL + Constance.URL_TOOL_FREE_COUNT, freeCountTool,callBack);
    }


    /**
     * 调取接口获取已发放列表
     */
    public static void getGrantedToolsList(RP_ToolSysSet mToolSystemSet, Response_loadPoliceInfo mPoliceInfo, Rp_loadPrisonerInfo mPrisoner, RP_StationInfo mStation, CustomNetCallBack callBack) {
        RQ_GetGrantedTools rq_getGrantedTools = new RQ_GetGrantedTools();
        rq_getGrantedTools.setCus_number(mPoliceInfo.getCus_number() + "");
        rq_getGrantedTools.setGive_object(mToolSystemSet.getGive_object());
        if (mStation != null) {
            rq_getGrantedTools.setStation_id(mStation.getStation_id());
        }
        if (mPrisoner != null) {
            rq_getGrantedTools.setUser_id(mPrisoner.getPrisoner_id());
        }
        HttpRqUtils.httpPost(Constance.BASE_URL + Constance.URL_TOOL_GET_GRANTED_TOOLS, rq_getGrantedTools,callBack);
    }
}
